package cn.tfyhyc.springcloud.service.impl;

import cn.tfyhyc.springcloud.service.ICustomMessageProvider;
import cn.tfyhyc.springcloud.stream.CustomSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author 头发又黑又长
 * @Date 2022/10/18 23:36
 * @email zwb15083976291@163.com
 */

/**
 * 自定义管道
 */
@Slf4j
@EnableBinding(CustomSource.class) // 自定义的消息推出通道
public class ICustomMessageProviderImpl implements ICustomMessageProvider {

    @Resource(name = "custom_output") // 存在多个推出通道需要指定bean 的名称
    private MessageChannel customOutput;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        Message<String> message = MessageBuilder.withPayload("customOutput:\t" + serial).build();
        customOutput.send(message);
        log.info("custom 生产者发送消息------------------------------" + serial);
        return serial;
    }
}
